-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: Extend ChatClient to leverage native structured output from ChatModel implementations #4890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
040697e to
5aff1d3
Compare
8ba7427 to
569ac6f
Compare
|
This pull request is very much needed, I don't know when it can be used. |
Implement StructuredOutputChatOptions interface to provide unified structured output support across AI providers. This enables AI models that provide built-in structured output to natively generate JSON responses that conform to a specified schema without additional prompt engineering. Models that provide structured response should implement the StructuredOutputChatOptions. To activate the native over the ChatClient prompt-based structured output response**,** you need to add the AdvisorParams.WITH_NATIVE_STRUCTURED_OUTPUT advisor parameter to your ChatClient configuration. - Add StructuredOutputChatOptions interface with getOutputSchema/setOutputSchema methods - Implement interface in AnthropicChatOptions, OpenAiChatOptions, and VertexAiGeminiChatOptions - Update AnthropicApi to support output_format parameter and add structured-outputs-2025-11-13 beta version - Add ChatClientAttributes for STRUCTURED_OUTPUT_SCHEMA and STRUCTURED_OUTPUT_NATIVE - Enhance ChatModelCallAdvisor to set output schema when native structured output is enabled - Update DefaultChatClient to handle native structured output via context attributes - Configure BeanOutputConverter to mark all fields as required in generated JSON schemas - Add AdvisorParams.WITH_NATIVE_STRUCTURED_OUTPUT for easy activation via ChatClient - Add integration tests for native structured output across all three providers Fixes spring-projects#4889 Addresses spring-projects#4463 Part of spring-projects#2787 Signed-off-by: Christian Tzolov <[email protected]>
Signed-off-by: Christian Tzolov <[email protected]>
Signed-off-by: Christian Tzolov <[email protected]>
Signed-off-by: Christian Tzolov <[email protected]>
Signed-off-by: Christian Tzolov <[email protected]>
- Implement StructuredOutputChatOptions interface in GoogleGenAiChatOptions - Add responseSchema field and related getter/setter methods - Add outputSchema bridge methods for unified Spring AI API - Update GoogleGenAiChatModel to handle responseSchema configuration - Add integration tests for both native and unified structured output APIs - Include tests for ChatClient with native structured output advisor - Update VertexAI Gemini tests with consistent naming and structured output support Signed-off-by: Christian Tzolov <[email protected]>
569ac6f to
d3bad12
Compare
|
|
||
| // @formatter:off | ||
| ActorsFilms actorsFilms = ChatClient.create(this.chatModel).prompt() | ||
| .advisors(AdvisorParams.ENABLE_NATIVE_STRUCTURED_OUTPUT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think having a top level chat client property or even an option at ChatClient level to enable the native structured output be better than Advisor param?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created #4946 to track this.
|
Squashed, rebased and merged as 195c4fd |
Add ChatClient support for utilizing native structured output capabilities provided by underlying ChatModel implementations (Anthropic, OpenAI, Vertex AI Gemini).
Implement StructuredOutputChatOptions interface to provide unified structured output
support across AI providers. This enables AI models that provide built-in structured
output to natively generate JSON responses that conform to a specified schema
without additional prompt engineering.
Models that provide structured response should implement the StructuredOutputChatOptions.
To activate the native over the ChatClient prompt-based structured output response**,**
you need to add the AdvisorParams.WITH_NATIVE_STRUCTURED_OUTPUT advisor parameter to your
ChatClient configuration.
Closes #4463
Fixes #4889
Part of #2787